import BNodeComposite from "../base/BNodeComposite";
import {ActionResult} from "../BTreeActionResult";
import BNode from "../base/BNode";
const {ccclass, property} = cc._decorator;
@ccclass
export default class BNodeSelector extends BNodeComposite {
    private m_iRuningIndex: number = 0;
    private memory:boolean = true;
    public enter(): void {
        this.m_iRuningIndex = 0;
        this.memory = this.getParameter("memory");
    }

    public excute(): ActionResult {
        if (this.m_iRuningIndex >= this.m_lstChildren.length) {
            return ActionResult.FAILURE;
        }

        let node: BNode = this.m_lstChildren[this.m_iRuningIndex];

        let res: ActionResult = node.runNode();

        if (res == ActionResult.SUCCESS)
            return ActionResult.SUCCESS;

        if (res == ActionResult.FAILURE) {
            this.m_iRuningIndex++;
        }
        return ActionResult.RUNNING;
    }
}
